#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1e4+10;
int n,m,d[MAXN],f[2][510],g[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();m=read();
	int cur=0;
	for(int i=1;i<=n;++i)
	{
		cur^=1;
		d[i]=read();
		for(int j=0;j<=m;++j)
		{
			f[cur][j]=0;
			if(j)f[cur][j]=max(f[cur][j],f[cur^1][j-1]+d[i]),g[i+j]=max(g[i+j],f[cur][j]);
			else f[cur][j]=max(f[cur][j],g[i]),g[i+1]=max(g[i+1],f[cur][j]);
		}
	}
	printf("%d\n",f[cur][0]);
	return 0;
}
